#pragma once
#include "SFML/System\Win32/Thread.hpp"
#include "SFML/System.hpp"
#include <vector>
#include "../Vocoder/SampleMarker.h"

class Modulator;
class Carrier;
class Vocoder;
class PlayerThread;
class PerformanceMonitor;

/*
Extension of SFML's thread API.
VocoderThread asks modulator and carrier for samples, vocodes them with Vocoder's help.
Then adds the resulting sample to PlayerThread that will eventually output the vocoded audio
*/
class VocoderThread :
	public sf::Thread
{
public:
	VocoderThread(void);
	~VocoderThread(void);

	void Initialize(Modulator* modulator, Carrier* carrier, Vocoder* vocoder, PlayerThread* playerThread, PerformanceMonitor* performanceMonitor, unsigned int windowLength);

	//Thread methods overridden
    virtual void Run();
    virtual void Stop();

private:
	volatile bool isRunning;
	sf::Mutex mutex;
	Modulator* modulator;
	Carrier* carrier;
	Vocoder* vocoder;
	PlayerThread* playerThread;
	PerformanceMonitor* performanceMonitor;
	unsigned int windowLength;

	std::vector<short> modulatorBuf;
	std::vector<short> carrierBuf;
	std::vector<short> vocoderBuf;
	std::vector<SampleMarker> sampleMarkers;

};
